"use strict";
function pathRegexp(path) {
    var paramNames = [];
    path = path.replace(/((\*{1}(?=\/))|(\*(1)(?=$)))/g, "[0-9a-zA-Z\-_]*") //把*替换成 [0-9a-zA-Z_\-]*
        .replace(/(:(.*?(?=\/)))|(:(.*?(?=$)))/g, function () {
            var len = arguments.length - 3;
            for (var i = 0; i < len; i++) {
                var avg = arguments[i + 1];

                if (typeof avg === "string" && avg[0] !== ":") {
                    paramNames.push(avg);
                }
            }
            return "([0-9a-zA-Z\-_]*)";
        }) //把:xxx替换成 [0-9a-zA-Z_\-]*
        .replace(/\/$/g, "") //  /article/:id/ 转换成 /artilce/:id
        .replace(/\//g, "\\\/"); //将/转换为 \/


    var regexp = new RegExp("^" + path + "\\/?$");
    regexp.paramNames = paramNames;
    return regexp;
}


module.exports = pathRegexp;


